package manager;

import java.util.List;

import util.HibernateSessionFactory;

import dao.CompilerDAO;
import model.Compiler;

/**
 * Managing Compiler, using singleton
 * @author xbingo
 *
 */
public class CompilerManager {
	private static CompilerManager compilerManager = new CompilerManager();
	private static CompilerDAO compilerDao = new CompilerDAO();
	
	private static final String DEFAULT_LANGUAGE = "C++";
	private static final String DEFAULT_NAME = "GNU C++";
	private static final String DEFAULT_PATH = "g++";
	private static final String DEFAULT_ARGUMENTS = "";
	
	private CompilerManager() {
		
	}

	/**
	 * 
	 * @return instance of CompilerManager
	 */
	public static CompilerManager getCompilerManager() {
		return compilerManager;
	}
	
	/**
	 * 
	 * @return compiler dao
	 */
	public CompilerDAO getCompilerDao() {
		return compilerDao;
	}
		
	/**
	 * 
	 * @return the default compiler
	 */
	public Compiler getDefaultCompiler(){
		//initialize the default compiler
		Compiler defaultCompiler = new Compiler();
		defaultCompiler.setLanguage(DEFAULT_LANGUAGE);
		defaultCompiler.setName(DEFAULT_NAME);
		defaultCompiler.setPath(DEFAULT_PATH);
		defaultCompiler.setArguments(DEFAULT_ARGUMENTS);
		List<Compiler> list = compilerDao.findByName(defaultCompiler.getName());
		if(list.size() == 0){
			compilerDao.save(defaultCompiler);
			return defaultCompiler;
		}else{
			return list.get(0);
		}
	}
}
